from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time



#创建谷歌浏览器对象
a = webdriver.Chrome()
#打开度小满理财系统
a.get("http://localhost:90")
#窗口最大化
a.maximize_window()

# #还没有账号？去注册
# a.find_element(By.LINK_TEXT,"还没有账号？去注册").click()
# # 请输入您的用户名
# a.find_element(By.XPATH,'/html/body/div/div/div/form/div[1]/input').send_keys("哈登")
# # # 请输入密码
# a.find_element(By.XPATH,'/html/body/div/div/div/form/div[2]/input').send_keys("123456")
# # # 请重复密码
# WebDriverWait(a,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="repassword"]')))
# a.find_element(By.XPATH,'//*[@id="repassword"]').send_keys("123456")
# time.sleep(2)
# # # 点击注册按钮
# a.find_element(By.ID,"login_btn").click()
#输入用户名
a.find_element(By.XPATH,'/html/body/div/div/div/form/div[1]/input').send_keys("admin")
#输入密码
a.find_element(By.ID,"password").send_keys("123456")
#点击立即登录按钮
a.find_element(By.XPATH,'/html/body/div/div/div/form/div[3]/button').click()
#等待显示系统首页
WebDriverWait(a, 10, 0.5).until(EC.presence_of_element_located((By.CLASS_NAME, 'navbar-brand')))
#点击用户信息管理
a.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a').click()
#点击用户信息
time.sleep(1)
a.find_element(By.XPATH,'//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a').click()
#点击新增按钮
a.find_element(By.XPATH,'//*[@id="user_add_modal_btn"]').click()
#强制等待1秒
time.sleep(1)
#填写用户名密码
a.find_element(By.CSS_SELECTOR,'#username_add_input').send_keys("伦纳德")
a.find_element(By.CSS_SELECTOR,'#password_add_input').send_keys("123456")
#点击保存按钮
a.find_element(By.CSS_SELECTOR,'#user_save_btn').click()
#强制等待三秒
time.sleep(3)
#退出浏览器
a.quit()


